home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_016 / source.files / remalloc.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  65 lines

  1. /** RemAlloc.c **************************************************************/
  2. /*  ChipAlloc(), ExtAlloc(), RemAlloc(), RemFree().                */
  3. /*  ALLOCators which REMember the size allocated, for simpler freeing.        */
  4. /*                                                                          */
  5. /* Date      Who Changes                                                    */
  6. /* --------- --- -----------------------------------------------------------*/
  7. /* 16-Jan-86 sss Created from DPaint/DAlloc.c                               */
  8. /* 23-Jan-86 jhm Include Compiler.h, check for size > 0 in RemAlloc.        */
  9. /* 25-Jan-86 sss Added ChipNoClearAlloc,ExtNoClearAlloc                     */
  10. /*                                                                      */
  11. /* By Jerry Morrison and Steve Shaw, Electronic Arts.                       */
  12. /* This software is in the public domain.                                  */
  13. /*                                                                      */
  14. /* This version for the Commodore-Amiga computer.                       */
  15. /*                                                                         */
  16. /****************************************************************************/
  17. #ifndef COMPILER_H
  18. #include "iff/compiler.h"
  19. #endif
  20.  
  21. #include "exec/nodes.h"
  22. #include "exec/memory.h"
  23. #include "iff/remalloc.h"
  24.  
  25. /** RemAlloc ****************************************************************/
  26. UBYTE *RemAlloc(size,flags) LONG size, flags; {
  27.     register LONG *p = NULL;    /* (LONG *) for the sake of p++, below */
  28.     register LONG asize = size+4;
  29.     if (size > 0)
  30.     p = (LONG *)AllocMem(asize,flags);
  31.     if (p != NULL)
  32.     *p++ = asize;    /* post-bump p to point at clients area*/
  33.     return((UBYTE *)p);
  34.     }
  35.  
  36. /** ChipAlloc ***************************************************************/
  37. UBYTE *ChipAlloc(size) LONG size; {
  38.     return(RemAlloc(size, MEMF_CLEAR|MEMF_PUBLIC|MEMF_CHIP));
  39.     }
  40.     
  41. /** ChipNoClearAlloc ********************************************************/
  42. UBYTE *ChipNoClearAlloc(size) LONG size; {
  43.     return(RemAlloc(size, MEMF_PUBLIC|MEMF_CHIP));
  44.     }
  45.     
  46. /** ExtAlloc ****************************************************************/
  47. UBYTE *ExtAlloc(size) LONG size; {
  48.     return(RemAlloc(size, MEMF_CLEAR|MEMF_PUBLIC));
  49.     }
  50.  
  51. /** ExtNoClearAlloc *********************************************************/
  52. UBYTE *ExtNoClearAlloc(size) LONG size; {
  53.     return(RemAlloc(size, MEMF_PUBLIC));
  54.     }
  55.  
  56. /** RemFree *****************************************************************/
  57. UBYTE *RemFree(p) UBYTE *p; {
  58.     if (p != NULL) {
  59.     p -= 4;
  60.     FreeMem(p, *((LONG *)p));
  61.     }
  62.     return(NULL);
  63.     }
  64.  
  65.